import AbstractCanvas from './canvas'
import BulletModel from '@/model/bullet'
import tankCanvas from './tank'
import config from '@/config'
import _ from 'lodash'

class Bullet extends AbstractCanvas<BulletModel> {
    public render(): void {
        setInterval(() => this.createBullets(), config.tank.shotInterval)
    }

    protected createBullets() {
        tankCanvas.models.forEach((d) => {
            // 不让坦克同时发射子弹
            if (_.random(0, 100) % 2) {
                setTimeout(() => BulletModel.create(d).render(), _.random(0, 1500))
            }
        })
    }

    protected setCanvasId(): void {
        this.canvas.id = 'canvas-bullet'
    }
}

export default new Bullet()
